import { checkOrderExpress, getReturnExpressData } from "../../api/order";

Page({
  data: {
    infoData: {},
    order_id: '',
    flowList: [],
    tab: [
      { id: 0, title: '商家发货物流' }
    ],
    tabs: [
      { id: 0, title: '商家发货物流' },
      { id: 1, title: '用户归还物流' }
    ],
    activeTab: 0,
    status: ''
  },
  onLoad(options) {
    console.log('status', options)
    this.setData({
      order_id: options.order_id,
      status: options.status
    });
    this.getData();
  },
  getData() {
    checkOrderExpress(this.data.order_id).then(res => {
      const list = res.info && res.info.data ? res.info.data : [];
      for (let item of list) {
        if (item.time) {
          item.date = item.time.split(' ')[0];
          item.time = item.time.split(' ')[1];
        }
      }
      this.setData({ infoData: res, flowList: list });
    })
  },
  getReturn() {
    getReturnExpressData(this.data.order_id).then(res => {
      const list = res.info && res.info.data ? res.info.data : [];
      for (let item of list) {
        if (item.time) {
          item.date = item.time.split(' ')[0];
          item.time = item.time.split(' ')[1];
        }
      }
      this.setData({ infoData_return: res, flowList_return: list });
    })
  },
  handleTabClick({ index, tabsName }) {
    const {status} = this.data
    this.setData({
      [tabsName]: index,
    });
    if(status==44 ||status==45 ||status==63 ||status==65){
      if (index == 1) {
        this.getReturn();
      } else {
        this.getData();
      }
    }
  },
  copy() {
    my.setClipboard({
      text: this.data.infoData.logistics_no,
      success: () => {
        my.alert({
          content: '已复制',
          buttonText: '我知道了'
        })
      }
    });
  }
});
